package com.shiro.shiroweb.auth;

import lombok.extern.log4j.Log4j2;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 全局异常处理
 */
@ControllerAdvice
@Log4j2
public class CtrlExceptionHandler {
    /**
     *  拦截未授权页面
     */
    @ResponseStatus(value = HttpStatus.FORBIDDEN)
    @ExceptionHandler(UnauthorizedException.class)
    public String handleException(UnauthorizedException e){
        log.info("报错了");
        log.info(e.getMessage());
        return "403";

    }
    /**
     *  拦截未授权页面
     */
    @ResponseStatus(value = HttpStatus.FORBIDDEN)
    @ExceptionHandler(AuthenticationException.class)
    public String handleException2(AuthenticationException e){
        log.info("报错了2");
        log.info(e.getMessage());
        return "403";

    }

}
